package com.yyh.dao;

import com.yyh.domain.User;
import com.yyh.service.GoodsService;
import com.yyh.service.impl.GoodsServideImpl;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class UserDaoImpl {
    // 准备Scanner
    public static final Scanner INPUT = new Scanner(System.in);
    // 专门用户注册和登录功能的用户集合
    public static final LinkedList<User> USER_LIST = new LinkedList<>();
    //
    static {
        USER_LIST.add(new User("jack","123456","JK",18));
        USER_LIST.add(new User("tom","654321","t",20));
    }

    // 创建商品操作的业务对象
    GoodsService goodsService = (GoodsService) new GoodsServideImpl();

    public LinkedList<User> getData(){
        return USER_LIST;
    }

    public void add(User user){
        USER_LIST.add(user);
    }

    public User selectUserByUsernameAndPassword(User user){

        // 假设登录失败
       User success = null;

        // 遍历集合
        for (User loginUser : USER_LIST) {
            if(loginUser.equals(user)){
                success = loginUser;
                break;
            }
        }
        return success;
    }

    public void successHtml(User loginUser){
        outer:
        while (true) {
            System.out.println("登录成功\t\t欢迎："+ loginUser.getUserName());
            System.out.println("*****************************电器商城*******************************");
            System.out.println("1、商品购买");
            System.out.println("2、我的购物车");
            System.out.println("3、个人信息");
            System.out.println("4、注销");
            System.out.println("*****************************电器商城*******************************");
            System.out.println("请输入菜单:");
            int choice = INPUT.nextInt();

            switch(choice){
                case 1:
                    // 商品购买
                    goodsService.shopping();
                    break ;
                case 2:
                    // 我的购物车
                    break ;
                case 3:
                    // 个人信息
                    break ;
                default:
                    System.exit(0);
                    break ;
            }

        }

    }

}
